package com.bjesc_b2c.app.appraiset.adapter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;

import com.bjesc_b2c.app.appraiset.R;

import java.util.List;

import app.pinggushi.bjesc.com.baserecyclerview.adapter.CommonAdapter;
import app.pinggushi.bjesc.com.baserecyclerview.adapter.base.ViewHolder;
import master_bean.AppraiserBean;

/**
 * Created by yidong on 2017/5/31.
 */

public class MoveOrderAdapter extends CommonAdapter<AppraiserBean> implements View.OnClickListener{
    private int position;
    public EditText editText;
    public MoveOrderAdapter(Context context, int layoutId, List<AppraiserBean> datas) {
        super(context, layoutId, datas);
    }

    @Override
    protected void convertView(final ViewHolder holder, AppraiserBean selectBean, final int position) {
        this.position = position;
        holder.setText(R.id.tv_appraiser_name, selectBean.getName());
        ((EditText)holder.getView(R.id.ed_move_content)).addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
//                if ( holder.getItemViewType() == position) {//设置tag解决错乱问题
                    onContentFillListener.onContentFill(position, s.toString());
//                }
            }
        });

        holder.setOnClickListener(R.id.iv_iphone, this);
        if (selectBean.isSelected()) {
                holder.getView(R.id.ed_move_content).setVisibility(View.VISIBLE);
                holder.getView(R.id.iv_checked).setVisibility(View.VISIBLE);
                holder.setBackgroundRes(R.id.iv_checked, R.drawable.ic_selected);
                holder.setTextColorRes(R.id.tv_appraiser_name, R.color.colorFFFF7900);
            } else {
                holder.getView(R.id.ed_move_content).setVisibility(View.GONE);
                holder.setBackgroundRes(R.id.iv_checked, R.drawable.no_selected);
                holder.setTextColorRes(R.id.tv_appraiser_name, R.color.colorFF030303);
        }
    }
    private void call(String phone) {
        Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phone));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(intent);
    }

    @Override
    public void onClick(View v) {
        call(mDatas.get(position).getPhone());
    }


    private OnContentFillListener onContentFillListener;

    public interface OnContentFillListener {
        void onContentFill(int position, String price);
    }

    public void setOnContentFillListener(OnContentFillListener onContentFillListener) {
        this.onContentFillListener = onContentFillListener;
    }


}
